package com.safframework.server.core.handler.socket

import io.netty.channel.ChannelInitializer
import io.netty.channel.socket.SocketChannel
import io.netty.handler.codec.http.HttpObjectAggregator
import io.netty.handler.codec.http.HttpServerCodec


/**
 *
 * @FileName:
 *          com.safframework.server.core.handler.socket.NettySocketServerInitializer
 * @author: Tony Shen
 * @date: 2020-03-25 13:42
 * @version: V1.0 <描述当前版本功能>
 */
class NettySocketServerInitializer(
    private val webSocketPath: String,
    private val mListener: WebSocketListener<Any>
) : ChannelInitializer<SocketChannel>() {

    @Throws(Exception::class)
    public override fun initChannel(ch: SocketChannel) {
        val pipeline = ch.pipeline()

        pipeline.addLast(HttpServerCodec())
        pipeline.addLast(HttpObjectAggregator(65536))
        pipeline.addLast(ChannelActiveHandler(mListener))
        pipeline.addLast("common_handler", CustomerServerHandler(mListener))
    }
}